from qiniu import Auth, put_data

access_key = 'RTcYDjxjrl51cdLtuLdcDgFD7LMUurIrr673vV7I'
secret_key = 'LbF5R3rKOKr0xtbQXIJp2iGeoWeZZ7fkBoKrlNbY'
# 七牛云空间名称
bucket_name = 'info'


def storage(data):
    try:
        q = Auth(access_key, secret_key)
        token = q.upload_token(bucket_name)
        ret, info = put_data(token, None, data)
        # print(ret, info)
    except Exception as e:
        raise e

    if info.status_code != 200:
        raise Exception("上传图片失败")
    return ret["key"]


if __name__ == '__main__':
    file = '/home/tyh/test.log'
    with open(file, 'rb') as f:
        print(storage(f.read()))

    print("OK")